<?php echo $header; ?>
<div id="content">
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <?php if ($error_warning) { ?>
    <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <div class="box">
        <div class="heading">
            <h1><img src="view/image/colory.png" alt="" /> <?php echo $heading_title; ?></h1>
            <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
        </div>
        <div class="content">
            <div id="tabs" class="htabs"><a href="#tab-general"><?php echo $tab_general; ?></a><a href="#tab-data"><?php echo $tab_data; ?></a><a href="#tab-design"><?php echo $tab_design; ?></a></div>
            <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
                <div id="tab-general">
                    <div id="languages" class="htabs">
                        <?php foreach ($languages as $language) { ?>
                        <a href="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
                        <?php } ?>
                    </div>
                    <?php foreach ($languages as $language) { ?>
                    <div id="language<?php echo $language['language_id']; ?>">
                        <table class="form">
                            <tr>
                                <td><span class="required">*</span> <?php echo $entry_name; ?></td>
                                <td><input type="text" onblur="locdau();" id="colory_description[<?php echo $language['language_id']; ?>][name]" name="colory_description[<?php echo $language['language_id']; ?>][name]" size="100" value="<?php echo isset($colory_description[$language['language_id']]) ? $colory_description[$language['language_id']]['name'] : ''; ?>" />
                                    <?php if (isset($error_name[$language['language_id']])) { ?>
                                    <span class="error"><?php echo $error_name[$language['language_id']]; ?></span>
                                    <?php } ?></td>
                            </tr>
                            <tr>
                                <td><?php echo $entry_meta_description; ?></td>
                                <td><textarea name="colory_description[<?php echo $language['language_id']; ?>][meta_description]" cols="40" rows="5"><?php echo isset($colory_description[$language['language_id']]) ? $colory_description[$language['language_id']]['meta_description'] : ''; ?></textarea></td>
                            </tr>
                            <tr>
                                <td><?php echo $entry_meta_keyword; ?></td>
                                <td><textarea name="colory_description[<?php echo $language['language_id']; ?>][meta_keyword]" cols="40" rows="5"><?php echo isset($colory_description[$language['language_id']]) ? $colory_description[$language['language_id']]['meta_keyword'] : ''; ?></textarea></td>
                            </tr>
                            <tr>
                                <td><?php echo $entry_description; ?></td>
                                <td><textarea name="colory_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($colory_description[$language['language_id']]) ? $colory_description[$language['language_id']]['description'] : ''; ?></textarea></td>
                            </tr>
                        </table>
                    </div>
                    <?php } ?>
                </div>
                <div id="tab-data">
                    <table class="form">
                        <tr>
                            <td><?php echo $entry_parent; ?></td>
                            <td><select name="parent_id">
                                    <option value="0"><?php echo $text_none; ?></option>
                                    <?php foreach ($colories as $colory) { ?>
                                    <?php if ($colory['colory_id'] == $parent_id) { ?>
                                    <option value="<?php echo $colory['colory_id']; ?>" selected="selected"><?php echo $colory['name']; ?></option>
                                    <?php } else { ?>
                                    <option value="<?php echo $colory['colory_id']; ?>"><?php echo $colory['name']; ?></option>
                                    <?php } ?>
                                    <?php } ?>
                                </select></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_store; ?></td>
                            <td><div class="scrollbox">
                                    <?php $class = 'even'; ?>
                                    <div class="<?php echo $class; ?>">
                                        <?php if (in_array(0, $colory_store)) { ?>
                                        <input type="checkbox" name="colory_store[]" value="0" checked="checked" />
                                        <?php echo $text_default; ?>
                                        <?php } else { ?>
                                        <input type="checkbox" name="colory_store[]" value="0" />
                                        <?php echo $text_default; ?>
                                        <?php } ?>
                                    </div>
                                    <?php foreach ($stores as $store) { ?>
                                    <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                                    <div class="<?php echo $class; ?>">
                                        <?php if (in_array($store['store_id'], $colory_store)) { ?>
                                        <input type="checkbox" name="colory_store[]" value="<?php echo $store['store_id']; ?>" checked="checked" />
                                        <?php echo $store['name']; ?>
                                        <?php } else { ?>
                                        <input type="checkbox" name="colory_store[]" value="<?php echo $store['store_id']; ?>" />
                                        <?php echo $store['name']; ?>
                                        <?php } ?>
                                    </div>
                                    <?php } ?>
                                </div></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_keyword; ?></td>
                            <td><input type="text" name="keyword" id="keyword" value="<?php echo $keyword; ?>"  ondblclick="locdau();" /></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_image; ?></td>
                            <td valign="top"><div class="image"><img src="<?php echo $thumb; ?>" alt="" id="thumb" />
                                    <input type="hidden" name="image" value="<?php echo $image; ?>" id="image" />
                                    <br /><a onclick="image_upload('image', 'thumb');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb').attr('src', '<?php echo $no_image; ?>'); $('#image').attr('value', '');"><?php echo $text_clear; ?></a></div></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_top; ?></td>
                            <td><?php if ($top) { ?>
                                <input type="checkbox" name="top" value="1" checked="checked" />
                                <?php } else { ?>
                                <input type="checkbox" name="top" value="1" />
                                <?php } ?></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_column; ?></td>
                            <td><input type="text" name="column" value="<?php echo $column; ?>" size="1" /></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_sort_order; ?></td>
                            <td><input type="text" name="sort_order" value="<?php echo $sort_order; ?>" size="1" /></td>
                        </tr>
                        <tr>
                            <td><?php echo $entry_status; ?></td>
                            <td><select name="status">
                                    <?php if ($status) { ?>
                                    <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                                    <option value="0"><?php echo $text_disabled; ?></option>
                                    <?php } else { ?>
                                    <option value="1"><?php echo $text_enabled; ?></option>
                                    <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                                    <?php } ?>
                                </select></td>
                        </tr>
                    </table>
                </div>
                <div id="tab-design">
                    <table class="list">
                        <thead>
                            <tr>
                                <td class="left"><?php echo $entry_store; ?></td>
                                <td class="left"><?php echo $entry_layout; ?></td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="left"><?php echo $text_default; ?></td>
                                <td class="left"><select name="colory_layout[0][layout_id]">
                                        <option value=""></option>
                                        <?php foreach ($layouts as $layout) { ?>
                                        <?php if (isset($colory_layout[0]) && $colory_layout[0] == $layout['layout_id']) { ?>
                                        <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                                        <?php } else { ?>
                                        <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                                        <?php } ?>
                                        <?php } ?>
                                    </select></td>
                            </tr>
                        </tbody>
                        <?php foreach ($stores as $store) { ?>
                        <tbody>
                            <tr>
                                <td class="left"><?php echo $store['name']; ?></td>
                                <td class="left"><select name="colory_layout[<?php echo $store['store_id']; ?>][layout_id]">
                                        <option value=""></option>
                                        <?php foreach ($layouts as $layout) { ?>
                                        <?php if (isset($colory_layout[$store['store_id']]) && $colory_layout[$store['store_id']] == $layout['layout_id']) { ?>
                                        <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                                        <?php } else { ?>
                                        <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                                        <?php } ?>
                                        <?php } ?>
                                    </select></td>
                            </tr>
                        </tbody>
                        <?php } ?>
                    </table>
                </div>
            </form>
        </div>
    </div>
</div>
<script type='text/javascript'>

    function locdau() {


    var str = (document.getElementById("colory_description[<?php echo $this->config->get('config_language_id'); ?>][name]").value);// lấy chuỗi dữ liệu nhập vào từ form có tên title

    str= str.toLowerCase();// chuyển chuỗi sang chữ thường để xử lý

    /* tìm kiếm và thay thế tất cả các nguyên âm có dấu sang không dấu*/

    str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");

    str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");

    str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");

    str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");

    str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");

    str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");

    str= str.replace(/đ/g,"d");

    str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-");

    /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */

    str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1-

    str= str.replace(/^\-+|\-+$/g,"");//cắt bỏ ký tự - ở đầu và cuối chuỗi
	
	
    document.getElementById("keyword").value = str;// xuất kết quả xữ lý ra keyword

}

</script>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script> 
<script type="text/javascript"><!--
    <?php foreach ($languages as $language) { ?>
    CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});
<?php } ?>
//--></script> 
<script type="text/javascript"><!--
function image_upload(field, thumb) {
$('#dialog').remove();
	
$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
$('#dialog').dialog({
title: '<?php echo $text_image_manager; ?>',
close: function (event, ui) {
if ($('#' + field).attr('value')) {
$.ajax({
url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>&image=' + encodeURIComponent($('#' + field).val()),
dataType: 'text',
success: function(data) {
$('#' + thumb).replaceWith('<img src="' + data + '" alt="" id="' + thumb + '" />');
}
});
}
},	
bgiframe: false,
width: 800,
height: 400,
resizable: false,
modal: false
});
};
//--></script> 
<script type="text/javascript"><!--
$('#tabs a').tabs(); 
$('#languages a').tabs();
//--></script> 
<?php echo $footer; ?>